package store.lunangangster.engine.impl.service;

import store.lunangangster.engine.ProcessEngineConfiguration;
import store.lunangangster.engine.impl.cmd.Command;
import store.lunangangster.engine.impl.cmd.DeploymentDeleteCmd;
import store.lunangangster.engine.impl.interceptor.CommandContext;
import store.lunangangster.engine.impl.query.DeploymentQuery;
import store.lunangangster.engine.impl.query.DeploymentQueryImpl;
import store.lunangangster.engine.impl.query.ProcessDefinitionQuery;
import store.lunangangster.engine.impl.query.ProcessDefinitionQueryImpl;
import store.lunangangster.engine.impl.repository.DeploymentBuilderImpl;
import store.lunangangster.engine.repository.DeploymentBuilder;
import store.lunangangster.engine.service.RepositoryService;

public class RepositoryServiceImpl extends ServiceImpl implements RepositoryService {

  public RepositoryServiceImpl(
      ProcessEngineConfiguration processEngineConfiguration) {
    super(processEngineConfiguration);
  }

  @Override
  public DeploymentBuilder createDeployment() {
    return executor.execute(new Command<DeploymentBuilder>() {
      @Override
      public DeploymentBuilder execute(CommandContext commandContext) {
        return new DeploymentBuilderImpl();
      }
    });
  }

  @Override
  public DeploymentQuery createDeploymentQuery() {
    return executor.execute(new Command<DeploymentQuery>() {
      @Override
      public DeploymentQuery execute(CommandContext commandContext) {
        return new DeploymentQueryImpl(executor);
      }
    });
  }

  @Override
  public ProcessDefinitionQuery createProcessDefinitionQuery() {
    return executor.execute(new Command<ProcessDefinitionQuery>() {
      @Override
      public ProcessDefinitionQuery execute(CommandContext commandContext) {
        return new ProcessDefinitionQueryImpl(executor);
      }
    });
  }

  @Override
  public void deleteDeployment(String deploymentId) {
    executor.execute(new DeploymentDeleteCmd(deploymentId));
  }

  @Override
  public void deleteDeployment(String deploymentId, boolean cascade) {
    executor.execute(new DeploymentDeleteCmd(deploymentId));
  }
}
